// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database();
// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const wxContext = cloud.getWXContext()
    var result = await db.collection('block').where({
      user_id: wxContext.OPENID,
    }).get();
    if (result.data[0] != null) {
      await db.collection('block').doc(result.data[0]._id).update({
        data: {
          block: true,
        }
      });
      return {
        msg: "ok",
      }
    } else
      return {
        msg: "error:block表中无对应user_id"
      }
  } catch (e) {
    console.error(e)
  }

}